package com.fyt.controller;

import com.fyt.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class RedisController {
    @Autowired
    private RestTemplate restTemplate;

    private static final String redisProvide = "http://redisProvider/redis/";
    /**
     * redis通过key获取value
     * @param key
     * @return
     */
    @GetMapping("/redisTest/get/{key}")
    public String get(@PathVariable("key") String key){
        String url = redisProvide+"get/";
        System.out.println(url);
        System.out.println(key);
        return restTemplate.getForObject(url+key,String.class);
    }

    @GetMapping("/redisTest/save/{key}/{value}")
    public R  save(@PathVariable("key") String key,@PathVariable("value") String value){
        return null;
    }

    /**
     * redis删除key
     * @param key
     * @return
     */
    @GetMapping("/redisTest/delete/{key}")
    public R  delete(@PathVariable("key")String key){
        return null;
    }

    /**
     * redis通过key修改<key,value>
     * @param key
     * @param value
     * @return
     */
    @RequestMapping("/redisTest/update/{key}/{value}")
    public R update(@PathVariable("key") String key, @PathVariable("value") String value){
        return null;
    }

}
